{% extends "base.html" %}
{% load get_item %}
{% block header %}定时任务管理{% endblock %}
{% block content %}
<div class="card shadow-sm rounded p-4 mb-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h4 class="mb-0">定时任务列表</h4>
        <a href="/add_task/" class="btn btn-success">添加新任务</a>
    </div>
    <div class="table-responsive">
        <table class="table table-bordered align-middle">
            <thead class="table-light">
                <tr>
                    <th>任务名称</th>
                    <th>任务路径</th>
                    <th>定时表达式</th>
                    <th>备注</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for task in page_obj %}
                <tr>
                    <td>{{ task.name }}</td>
                    <td>{{ task_labels|get_item:task.task|default:task.task }}</td>
                    <td>{{ task.crontab }}</td>
                    <td>{{ task.remark }}</td>
                    <td>
                        <a href="/edit_task/{{ task.id }}/" class="btn btn-sm btn-primary">编辑</a>
                        <a href="/delete_task/{{ task.id }}/" class="btn btn-sm btn-danger ms-1">删除</a>
                    </td>
                </tr>
                {% empty %}
                <tr><td colspan="5" class="text-center">暂无任务信息</td></tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    <nav>
        <ul class="pagination justify-content-center">
            {% if page_obj.number > 1 %}
            <li class="page-item"><a class="page-link" href="?page=1">首页</a></li>
            {% endif %}
            {% if page_obj.has_previous %}
            <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a></li>
            {% endif %}
            <li class="page-item disabled"><span class="page-link">第 {{ page_obj.number }} 页 / 共 {{ page_obj.paginator.num_pages }} 页</span></li>
            {% if page_obj.has_next %}
            <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a></li>
            {% endif %}
            {% if page_obj.number < page_obj.paginator.num_pages %}
            <li class="page-item"><a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">尾页</a></li>
            {% endif %}
        </ul>
    </nav>
</div>
{% endblock %}
